<?php defined("MAIN_DIR") or die("No direct access");

require_once ADMIN.HEADFILE;
?>
<div align="left">
<h1>Выбор банка</h1><?php
$banks_query = "select `B`.`bank_id`,`B`.`name`,COUNT(`A`.`atm_id`) as `count` from `bank` as `B`,`atm` as `A` where `B`.`bank_id` = `A`.`bank_id` and `B`.`city_id` = '$_SESSION[city_admin]' group by `B`.`bank_id` order by `B`.`name`";

$limit = 10;
$banks_result = mysql_query($banks_query);
$count = mysql_num_rows($banks_result);
$page = 1;
if (isset($_GET['page']))
	$page = $_GET['page'];
$max_page = ceil($count/$limit);
if ($max_page == 0)
	$max_page++;
if ($page > $max_page)
	$page = $max_page;
elseif ($page < 1)
	$page = 1;
$start_list = (ceil($page)-1)*$limit;
$banks_query .= " limit $start_list,$limit";
$banks_result = mysql_query($banks_query);
$banks_count = mysql_num_rows($banks_result);
?>
<table cellpadding="5" cellspacing="0" class='light'>
	<tr id='header'>
		<td width="300px" style="border-bottom:1px gray solid">Название</td>
		<td width="30px" style="border-bottom:1px gray solid">Количество</td>
	</tr><?php
	while ($bank_row = mysql_fetch_array($banks_result))
	{
		?><tr>
			<td><a href='/admin/atms/<?php echo $bank_row['bank_id']?>'><?php echo $bank_row['name']?></td>
			<td><?php echo $bank_row['count']?></td>
		</tr><?php
	}
?></table>
<br /><a href='/admin/atms/add'>Добавить банкомат</a>
<br /><?php require_once APP."pageskin.php"; ?>
</div>

<?php require_once ADMIN.FOOTERFILE; ?>